package util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Francis
 */
public class MD5Hash {
    
    private MD5Hash() {        
    }
    
    public static String createHash(String username, String email, String password) {
        try {
            String s = username + email + password;
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.update(s.getBytes(), 0, s.length());
            BigInteger bi = new BigInteger(1, m.digest());
            //System.out.println("MD5: " + bi.toString(16));
            //System.out.println("MD5: " + bi.toString(16).substring(0, 9));
            return bi.toString(16).substring(2, 11);
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(MD5Hash.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
    
    public static void main(String...args) {
        createHash("eeeeee", "eeeeee@eeeeee.com", "eeeeee");
    }

}
